<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //1、函数默认值允许是表达式
        function foo1(m = 1 + 1, n = m + 1) {
            console.log(m + n);
        }
        foo1();  //5

        //2、函数默认值允许是函数
        function foo2(add = function (m, n) { return m + n; }, a, b) {
            console.log(add(a, b));
        }
        foo2(undefined, 2, 3);  //5
        foo2(function (x, y) { return x - y }, 2, 3);  //-1

        //3、IIFE，允许使用立即执行函数表达式
        function foo3(m = 1, n = function (x) { return ++x; }(m)) {
            console.log(m+n);
        }
        foo3();  //3
    </script>
</body>

</html>